<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <link rel="icon" href="./logo.png">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <title>SimpleImages</title>
    <style>
    body {
    font-family: 'Arial', sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.container {
    max-width: 800px;
    width: 100%;
    background: white;
    padding: 40px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    margin: 0 auto;
}

.upload-area {
    border: 3px dashed #ccc;
    padding: 60px;
    text-align: center;
    margin-bottom: 40px;
    transition: background-color 0.3s ease;
    cursor: pointer;
    background-color: #fafafa;
}

.upload-area:hover {
    background-color: #f0f0f0;
}

.upload-area label {
    font-size: 1.2rem;
    color: #333;
    cursor: pointer;
    transition: color 0.3s ease;
}

.upload-area label:hover {
    color: #007bff;
}

form input[type="submit"] {
    display: inline-block;
    padding: 10px 20px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

form input[type="submit"]:hover {
    background-color: #0056b3;
}

.uploaded-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, 150px);
    gap: 20px;
    justify-content: center;
}

.uploaded-image {
    width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.uploaded-image:hover {
    transform: scale(1.05);
}
        .upload-preview {
            margin-bottom: 20px;
        }
        .upload-preview img {
            max-width: 100%;
            max-height: 300px;
            border-radius: 4px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        .upload-button {
            display: inline-block;
            padding: 10px 20px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        .upload-button:hover {
            background-color: #0056b3;
        }
    #copyright{
    position: fixed;
    bottom: 5%;
    right: 10%;
    background-color: #fff; 
    opacity:0.6;
    color: #000;
    border: 1px solid #000;
    padding: 4px;
  cursor: default;
}
.kaiyuan{
    text-decoration:none;
    color: #111;
}

/* 这下面一部分样式是AI(自部署)给补充的，因为当上传图片较多时会有小bug */
body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
}

.container {
    max-width: 600px;
    margin: auto;
    background: white;
    padding: 20px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
}

h1 {
    margin-bottom: 20px;
}

.uploaded-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, 150px);
    gap: 20px;
    overflow-y: auto; /* 添加滚动条 */
}

.uploaded-image {
    width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

/* 使用position: sticky;固定头部 */
.header {
    position: sticky;
    top: 0;
    background-color: white;
    padding: 20px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid #ccc;
}

/* 确保头部不会被滚动条覆盖 */
.header::after {
    content: "";
    display: block;
    clear: both;
}
    </style>
</head>
<body>
    <div class="container">
        <h1>SimpleImages</h1>
        <form id="uploadForm" action="upload.php" method="post" enctype="multipart/form-data">
            <label for="image"><div class="upload-area">
                <input type="file" name="image" id="image" hidden>
                <label for="image">点击上传图片</label>
            </div></label>
            <div class="upload-preview" id="uploadPreview">
                <!-- 预览图片将在这里显示 -->
            </div>
            <button type="button" class="upload-button" id="uploadButton">确认上传</button>
        </form>
        <div class="uploaded-images">
            <?php
                // 动态载入已上传的图片
                $images = glob("uploads/*.*");
                foreach($images as$image) {
                    $image_url = 'http://你的域名/' .$image; // 假设的图片URL
                    echo '<div class="uploaded-image-container">';
                    echo '<img src="'.$image.'" class="uploaded-image" data-url="'.$image_url.'" />';
                    echo '</div>';
                }
            ?>
        </div>
    </div>
    <center>
        <div id="copyright">
            CopyRight &copy;2024 YourWebsite<br>
            Powerd by <a href="https://gitee.com/LiuJiaxu1231/SimpleImages/" class="kaiyuan">SimpleImages</a>
            </div>
        </center>
    <script>
        document.getElementById('image').addEventListener('change', function(event) {
            var file = event.target.files[0];
            if (file) {
                var reader = new FileReader();
                reader.onload = function(e) {
                    var img = document.createElement('img');
                    img.src = e.target.result;
                    document.getElementById('uploadPreview').appendChild(img);
                };
                reader.readAsDataURL(file);
                document.getElementById('uploadButton').addEventListener('click', function() {
                    document.getElementById('uploadForm').submit();
                });
            }
        });
    </script>
        <script>
        document.querySelectorAll('.uploaded-image').forEach(function(img) {
            img.addEventListener('click', function(event) {
                var url = event.target.getAttribute('data-url');
                navigator.clipboard.writeText(url).then(function() {
                    console.log('复制成功: ' + url);
                }).catch(function(err) {
                    console.error('复制失败: ', err);
                });
            });
        });
    </script>
</body>
</html>
